﻿using System;
using Entities;
using WebLog;
using System.Collections.Generic;

namespace Data
{
    public sealed class StatisticData
    {
        public void InsertStatistic(List<Statistic> list)
        {
            DataBase bd = new DataBase();

            try
            {
                bd.Connect();
                bd.BeginTransaction();

                foreach (Statistic s in list)
                {
                    bd.ProcedureSqlName("INSERTAR_ESTADISTICA");
                    bd.AssignInt("@ID_SEXO", s.sexId);
                    bd.AssignInt("@ID_ESTADO_CIVIL", s.civilStatusId);
                    bd.AssignInt("@ID_REGION", s.regionId);
                    bd.AssignInt("@ID_COMUNA", s.communeId);
                    bd.AssignDateTime("@FECHA_NACIMIENTO", s.birthDate);
                    bd.AssignInt("@ID_VOTACION", s.votingId);
                    bd.AssignInt("@ID_CANDIDATO", s.candidateId);
                    bd.AssignDateTime("@FECHA_REGISTRO", s.register);
                    bd.AssignBool("@CANDIDATO_BLANCO", s.candidateWhite);
                    int escalar = (int)bd.ExecuteNonQuery();
                    
                }

                bd.CommitTransaction();

            }
            catch (Exception e)
            {
                Logger logger = Logger.GetInstance;
                logger.WriteLog(e);
                bd.RollbackTransaction();
            }
            finally
            {

                bd.Disconnect();
                bd.ReleaseResources();
            }

        }
    }
}
